package com.bbg.amyam.domain.model;

import com.bbg.amyam.domain.enumtype.ActiveStatusCode;
import com.bbg.amyam.domain.enumtype.StateCode;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.ObjectOutputStream;
import java.util.HashSet;
import java.util.Set;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.EnumType;
import javax.persistence.Enumerated;
import javax.persistence.FetchType;
import javax.persistence.ManyToMany;
import javax.persistence.ManyToOne;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Pattern;
import javax.validation.constraints.Size;
import org.springframework.roo.addon.javabean.RooJavaBean;
import org.springframework.roo.addon.jpa.activerecord.RooJpaActiveRecord;
import org.springframework.roo.addon.serializable.RooSerializable;
import org.springframework.roo.addon.tostring.RooToString;

@RooJavaBean
@RooToString
@RooSerializable
@RooJpaActiveRecord(finders = { "findSchoolsByShortNameEquals", "findSchoolsByShortNameLike", "findSchoolsByShortNameLikeAndActiveStatus" })
public class School {

    @NotNull
    @Column(unique = true)
    @Size(min = 2, max = 20)
    @Pattern(regexp = "[a-z|0-9]{2,20}")
    private String shortName;

    @NotNull
    @Size(max = 30)
    private String fullName;

    @Size(max = 60)
    private String address;

    @Size(max = 20)
    private String city;

    @Enumerated(EnumType.STRING)
    private StateCode stateCode;

    @Size(min = 5, max = 5)
    @Pattern(regexp = "[0-9]{5}")
    private String zipCode;

    @Enumerated(EnumType.ORDINAL)
    private ActiveStatusCode activeStatus;

    @ManyToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY)
    private Set<SchoolTag> tags = new HashSet<SchoolTag>();

    @Pattern(regexp = "[0-9]{3}-[0-9]{3}-[0-9]{4}")
    private String phone;

    private String schoolWebSite;

    private String logoURL;

    @NotNull
    @ManyToOne
    private Profile adminProfile;

    public static void main(String[] args) {
        Profile p = new Profile();
        School s1 = new School();
        NewsArticle s = new NewsArticle();
        try {
            if (s instanceof java.io.Serializable) {
                System.out.println("Serialized");
            } else {
                System.out.println("NOT Serialized!");
            }
            FileOutputStream fileOut = new FileOutputStream("employee.ser");
            ObjectOutputStream out = new ObjectOutputStream(fileOut);
            out.writeObject(s);
            out.close();
            fileOut.close();
        } catch (IOException i) {
            i.printStackTrace();
        }
    }
}
